<template>
  <div class="mod-fii__fiiuser">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.nlike_account$userName$t3$$company" placeholder="请输入关键词语" clearable></el-input>
      </el-form-item>

      <el-form-item>
        <el-select v-model="dataForm.type" placeholder="分类">
          <el-option v-for="item in dict.type" :key="item.code" :label="item.name" :value="parseInt(item.code)"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('fii:fiiuser:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('fii:fiiuser:delete')" type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="companyName" label="集团名称" header-align="center" align="center"></el-table-column>
      <el-table-column prop="account" label="账号" header-align="center" align="center" width="100"></el-table-column>
      <el-table-column prop="userName" label="姓名" header-align="center" align="center"></el-table-column>
      <el-table-column prop="type" label="账号类型" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.type === 1" size="small" type="danger">集团账号</el-tag>
          <el-tag v-if="scope.row.type === 2" size="small" type="danger">集团下属学校账号</el-tag>
          <el-tag v-if="scope.row.type === 3" size="small" type="danger">老师账号</el-tag>
          <el-tag v-if="scope.row.type === 4" size="small" type="danger">学生账号</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" header-align="center" align="center" width="100">
        <template v-slot="scope">
          <el-tag v-if="scope.row.status === 0" size="small" type="danger">停用</el-tag>
          <el-tag v-else size="small">启用</el-tag>
        </template>
      </el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="180">
        <template v-slot="scope">
          <el-button v-if="hasPermission('fii:fiiuser:update')" type="text" size="small" @click="resetPass(scope.row.id)">重置密码</el-button>
          <el-button v-if="hasPermission('fii:fiiuser:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('fii:fiiuser:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./fiiuser-add-or-update.vue";
import baseService from "@/service/baseService";
import ui from "@/utils/ui";
import { IObject } from "@/types/interface";
export default defineComponent({
  components: {
    AddOrUpdate
  },
  setup() {
    const state = reactive({
      getDataListURL: "/fii/fiiuser/page",
      getDataListIsPage: true,
      exportURL: "/fii/fiiuser/export",
      deleteURL: "/fii/fiiuser",
      resetUrl: "/fii/fiiuser/resetPwd",
      dict: {
        type: baseService.strDict("1:集团账号,2:集团下属学校账号,3:老师账号,4:学生账号")
      },
      deleteIsBatch: true,
      dataForm: {
        nlike_account$userName$t3$$company: "",
        userName: "",
        type: ""
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  watch: {},
  methods: {
    resetPass: function (id: number) {
      ui.confirm("确认重置密码", "确认重置密码", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        baseService.post(this.resetUrl, { id: id }).then((r: any) => {
          this.$message({
            message: "重置成功",
            type: "success",
            duration: 500
          });
        });
      });
      // 删除
    }
  }
});
</script>
